function userOperate() {


  this.tellnumber = localStorage.getItem('ACTIVE_USER')

  this.name
  this.pwd
  this.phone
  this.telreg = /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[189]))\d{8}$/
  this.pwdreg = /^\S*(?=\S{6,})(?=\S*\d)(?=\S*[A-Z])(?=\S*[a-z])(?=\S*[!@#$%^&*? ])\S*$/

  this.userMsg()
  this.userEvent()
}


userOperate.prototype.userMsg = function () {
  console.log(this.tellnumber);
  getuser({
    tellnumber: this.tellnumber
  }).then(res => {
    console.log(res);
    if (res.status) {
      if (res.data.username) {
        $(".inp_name")[0].placeholder = res.data.username
      } else {
        $(".inp_name")[0].placeholder = "设置昵称"
      }
    }
    $(".old_iphone").html(res.data.tellnumber)
  })

}

userOperate.prototype.userName = function () {
  deluser({
    tellnumber: this.tellnumber
  }).then(res => {
    console.log(res);
    if (res.status) {
      localStorage.removeItem('ACTIVE_USER')
      location.href = "../html/littleDuck.html"
    }
  })

}

userOperate.prototype.userEvent = function () {
  $(".content_wrap").click((e) => {
    let target = e.target
    if (target.classList.contains("del_user")) {
      console.log(123);
      this.userName()
    }


    //改用户名
    if (target.classList.contains("change_name")) {
      console.log(123);
      changeuser({
        tellnumber: this.tellnumber,
        username: $(".inp_name").val()
      }).then(res => {
        if (res.status) {
          alert("修改成功")
          $(".inp_name")[0].placeholder = $(".inp_name").val()
        }
      })

    }

    //改手机号
    if (target.classList.contains("old_iphone")) {
      $(target).css("display", "none")
      $(target).next().css("display", "block")
      //点击确认
      $(".change_iphone").click(() => {
        this.phone = $(".inp_iphone").val()
        $(".inp_iphone_tip").css("display", "none")
        if (this.telreg.test(this.phone)) {
          changeuser({
            tellnumber: this.tellnumber,
            Ntellnumber: $(".inp_iphone").val()
          }).then(res => {
            console.log(res);
            if (res.status) {
              const newIphone = $(".inp_iphone").val()
              $(".inp_iphone").css("display", "none")
              $(".old_iphone").next().css("display", "block")
              $(".old_iphone").html(newIphone)
              alert("修改成功")
              localStorage.setItem('ACTIVE_USER', newIphone)
            } else {
              console.log(123);
              $(".inp_iphone").css("display", "none")
              $(".old_iphone").css("display", "block")
            }
          })
        } else {
          $(".inp_iphone_tip").css("display", "block")
          // $(".inp_iphone").css("display", "none")
          // $(".old_iphone").css("display", "block")
        }

      })
    }

    //改密码
    if (target.classList.contains("change_pwd")) {
      this.pwd =$(".inp_pwd").val();
      $(".inp_pwd_tip").css("display", "none")
      if (this.pwdreg.test(this.pwd)) {
        changeuser({
          tellnumber: this.tellnumber,
          password: $(".inp_pwd").val()
        }).then(res => {
          if (res.status) {
            alert("重置成功")
          }
        })
      } else {
        $(".inp_pwd_tip").css("display", "block")
      }

    }

  })
}





new userOperate()